package com.itcp.itelpicture.domain.vo.communityVo;

import com.itcp.itelpicture.domain.po.community.CommunityPost;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 社区文章视图对象
 */
@Data
public class CommunityPostVO implements Serializable {
    /**
     * 文章ID
     */
    private Long id;

    /**
     * 文章标题
     */
    private String title;

    /**
     * 文章内容
     */
    private String content;

    /**
     * 文章摘要
     */
    private String summary;

    /**
     * 图片附件
     */
    private String imageUrl;

    /**
     * 作者ID
     */
    private Long userId;

    /**
     * 作者名称
     */
    private String userName;

    /**
     * 作者头像
     */
    private String userAvatar;

    /**
     * 用户简介
     */
    private String userProfile;

    /**
     * 当前用户的文章总数
     */
    private Long postNumber;

    /**
     * 所属社区ID
     */
    private Long communityId;

    /**
     * 所属社区名称
     */
    private String communityName;

    /**
     * 用于展示当前用户的其他文章
     */
    private List<PostDetailVO> postDetailVOList;

    /**
     * 浏览数
     */
    private Integer viewCount;

    /**
     * 点赞数
     */
    private Integer likeCount;

    /**
     * 收藏数
     */
    private Integer favourCount;

    /**
     * 评论数
     */
    private Integer commentCount;

    /**
     * 是否置顶
     */
    private Boolean isTop;

    /**
     * 是否精华
     */
    private Boolean isEssence;

    /**
     * 状态：0-已发布，1-待审核，2-已拒绝
     */
    private Integer status;

    /**
     * 标签列表
     */
    private List<String> tagList;

    /**
     * 是否已点赞
     */
    private Boolean hasLiked;

    /**
     * 是否已收藏
     */
    private Boolean hasFavorited;

    /**
     * 发布时间
     */
    private LocalDateTime createTime;

    /**
     * 将实体转换为视图对象
     * @param communityPost
     * @return
     */
    public static CommunityPostVO objToVo(CommunityPost communityPost) {
        if (communityPost == null) {
            return null;
        }
        CommunityPostVO communityPostVO = new CommunityPostVO();
        communityPostVO.setId(communityPost.getId());
        communityPostVO.setTitle(communityPost.getTitle());
        communityPostVO.setContent(communityPost.getContent());
        communityPostVO.setSummary(communityPost.getSummary());
        communityPostVO.setUserId(communityPost.getUserId());
        communityPostVO.setCommunityId(communityPost.getCommunityId());
        communityPostVO.setViewCount(communityPost.getViewCount());
        communityPostVO.setLikeCount(communityPost.getLikeCount());
        communityPostVO.setCommentCount(communityPost.getCommentCount());
        communityPostVO.setIsTop(communityPost.getIsTop());
        communityPostVO.setIsEssence(communityPost.getIsEssence());
        communityPostVO.setImageUrl(communityPost.getImageUrl());

        // 默认值设置
        communityPostVO.setHasLiked(false);
        communityPostVO.setHasFavorited(false);

        return communityPostVO;
    }


    private static final long serialVersionUID = 1L;
}